/**
 * 
 */
package edu.umuc.cmsc495_final_project;

import java.awt.BorderLayout;
import java.awt.FileDialog;
import java.awt.GridLayout;
import java.awt.TextArea;

import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JTabbedPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;
import java.awt.Font;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;

import javax.swing.SwingConstants;

import javax.swing.JSplitPane;

/**
 * @author paul.lipp
 * 
 */
public class Settings extends JFrame implements Serializable,  WindowFocusListener, WindowListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = -6007025937271928610L;
	DataBase db;// TODO change this.. this needs to either extend application,
				// or return db

	DefaultMutableTreeNode administratorCred;
	DefaultMutableTreeNode managerCred;
	DefaultMutableTreeNode hostessCred;
	DefaultMutableTreeNode serverCred;
	DefaultMutableTreeNode bartenderCred;
	DefaultMutableTreeNode cookCred;
	DefaultMutableTreeNode chefCred;

	JPanel contentPane;
	JPanel allEmployees;
	JPanel administrator;
	JPanel settings;
	JPanel addTables;
	JPanel removeTables;
	JPanel employees;
	JPanel notes;
	JPanel backupDatabase;
	JPanel loadDatabase;
	JPanel changeTaxRate;
	JPanel changeHours;

	JTree employeeTree;

	final JTabbedPane tabbedPane;// = new JTabbedPane(JTabbedPane.TOP);

	JButton btnSave;
	JButton btnBackupDatabase;
	JButton btnExportDatabase;
	JButton btnLoadDatabase;
	JButton btnNewDatabase;
	JButton btnChngTaxRate;
	JButton btnHours;
	JButton btnSaveHoursOfOp;
	JButton btnNewTableChair;
	JButton btnRemoveTableChair;
	JButton btnMakeTable;
	JButton btnCancelTable;
	JButton btnRemoveTable;
	JButton btnSaveTaxRate;

	JTextField txtFldQuant;
	JTextField txtFldRemoveQuant;
	JTextField taxRatesField;

	TextArea txtNotes1;
	TextArea txtNotes2;
	TextArea txtNotes3;

	JLabel lblTableType;
	JLabel lblTableQuant;

	JComboBox cmbTableType;
	JComboBox jcbOpeningTime;
	JComboBox jcbClosingTime;
	
	JFileChooser fc; 

	credential privelageLevel;

	String empIDNum;
	String firstName;
	String lastName;
	String notes1;
	String notes2;
	String notes3;

	int passkey;
	int tableID;
	int xCoordinate;
	int yCoordinate;
	int tableQuant;
	int selectedpane = 0;
	int hoursStart;
	int minStart;
	int hoursEnd;
	int minEnd;
	
	double taxRate;

	TableType tableType;
	RestaurantTime hoursOfOpOpen;
	RestaurantTime hoursOfOpClose;
	
	ArrayList<String> startTime;
	ArrayList<String> endTime;

	// constructor
	public Settings(DataBase db) {
		this.db = db;

		// setTitle("Team B - Restaurant POS System");
		setTitle("Settings & Setup");
		setVisible(true);
		setSize(450, 300);
		new centerScreen(this);
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);

		// creates all panes
		AllEmployeesPane();
		AdministratorPane();
		EmployeePane();
		DatabasePane();
		NotesPane();

		// Create a tabbed pane
		tabbedPane = new JTabbedPane();
		tabbedPane.addTab("Employees", allEmployees); // pane 0
		// if(/* current user credential level is administrator, show admin tab,
		// else dont*/)
		tabbedPane.addTab("Administrator", administrator); // pane 1
		tabbedPane.addTab("Employee", employees); // pane 2
		tabbedPane.addTab("Settings", settings); // pane 3
		tabbedPane.addTab("Notes", notes); // pane 4

		// Register a change listener
		tabbedPane.addChangeListener(new ChangeListener() {
			@Override
			public void stateChanged(ChangeEvent arg0) {
				JTabbedPane pane = (JTabbedPane) arg0.getSource();
				changeTab(pane.getSelectedIndex());

				if (pane.getSelectedIndex() == 0 || pane.getSelectedIndex() == 3)
					btnSave.setVisible(false);
				else
					btnSave.setVisible(true);
			}
		});

		contentPane.add(tabbedPane, BorderLayout.CENTER);

		// save button
		btnSave = new JButton("Save");
		btnSave.setVisible(false);
		contentPane.add(btnSave, BorderLayout.SOUTH);

		// allows window to close if moved away from
		addWindowFocusListener(this);
	}

	protected void addNewEmployee() {
		try {

			//db.addNewEmployee(new employee(lastName, firstName, generateEmpID(), privelageLevel, passkey));

			//System.out.println("employees" + db.getEmployees());
		} catch (Exception e) {
			System.err.println("error in adding new employee");
		}
	}

	//
	protected void changeTab(int selectedIndex) {
		// Get current tab
		selectedpane = selectedIndex;
	}

	// employee tree pane
	private void AllEmployeesPane() {
		allEmployees = new JPanel();
		allEmployees.setLayout(new GridLayout(1, 1));

		// Employee Tree
		DefaultMutableTreeNode top = new DefaultMutableTreeNode(/*
																 * Restruant
																 * name +
																 */"Employees");
		// TODO possibly switch trees to DefaultTreeModel ...
		// DefaultTreeModel newTop = new DefaultTreeModel();

		createNodes(top);
		employeeTree = new JTree(top);
		JScrollPane employeeTreeView = new JScrollPane(employeeTree);

		// employee information pane
		TextArea txtAreaEmployeeInformation = new TextArea();
		txtAreaEmployeeInformation.setEditable(false);

		// Split pane window
		JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, employeeTreeView, txtAreaEmployeeInformation);
		splitPane.setOneTouchExpandable(true);
		splitPane.setDividerLocation(150);

		// create split pane
		allEmployees.add(splitPane);
	}

	// admin pane
	private void AdministratorPane() {
		administrator = new JPanel();
		administrator.setLayout(null);

		// super admin label
		JLabel lblCreateAdmin = new JLabel("Create super-administrator account");
		lblCreateAdmin.setFont(new Font("Tahoma", Font.BOLD, 18));
		lblCreateAdmin.setBounds(36, 11, 361, 34);
		lblCreateAdmin.setHorizontalAlignment((int) JLabel.CENTER_ALIGNMENT);
		administrator.add(lblCreateAdmin);

		// first name label
		JLabel lblFirstName = new JLabel("First name:");
		lblFirstName.setBounds(136, 56, 150, 20);
		administrator.add(lblFirstName);

		// first name field
		final JTextField fldFirstName = new JTextField();
		fldFirstName.setBounds(136, 76, 150, 20);
		fldFirstName.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				firstName = fldFirstName.getText();
			}
		});
		administrator.add(fldFirstName);

		// last name label
		JLabel lblLastName = new JLabel("Last name:");
		lblLastName.setBounds(136, 101, 150, 20);
		administrator.add(lblLastName);

		// last name field
		final JTextField fldLastName = new JTextField();
		fldLastName.setBounds(136, 121, 150, 20);
		fldLastName.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				lastName = fldLastName.getText();
			}
		});
		administrator.add(fldLastName);

		// passkey label
		JLabel lblPasskey = new JLabel("Passkey:");
		lblPasskey.setBounds(136, 146, 150, 20);
		administrator.add(lblPasskey);

		// passkey field
		final JPasswordField fieldPass = new JPasswordField();
		fieldPass.setBounds(136, 166, 150, 20);
		fieldPass.addFocusListener(new FocusAdapter() {
			@SuppressWarnings("deprecation")
			@Override
			public void focusLost(FocusEvent arg0) {
				try {
					passkey = Integer.parseInt(fieldPass.getText());
				} catch (Exception e) {

				}
			}
		});
		administrator.add(fieldPass);
	}

	// employee pane
	private void EmployeePane() {
		employees = new JPanel();
		employees.setLayout(null);

		// employees label
		JLabel label = new JLabel("Add new employees");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setFont(new Font("Tahoma", Font.BOLD, 18));
		label.setBounds(36, 11, 361, 34);
		employees.add(label);

		// privelage level label
		JLabel lblPrivelageLevel = new JLabel("Privelage Level:");
		lblPrivelageLevel.setBounds(220, 46, 150, 20);
		employees.add(lblPrivelageLevel);

		// privelage level combo box
		final JComboBox lstPrivelageLevel = new JComboBox(credential.values());
		lstPrivelageLevel.setBounds(220, 66, 150, 20);
		lstPrivelageLevel.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent e) {
				switch (lstPrivelageLevel.getSelectedIndex()) {
				case 0: { // ADMINISTRATOR
					privelageLevel = credential.ADMINISTRATOR;
					break;
				}
				case 1: { // MANAGER
					privelageLevel = credential.MANAGER;
					break;
				}
				case 2: { // HOSTESS
					privelageLevel = credential.HOSTESS;
					break;
				}
				case 3: { // SERVER
					privelageLevel = credential.SERVER;
					break;
				}
				case 4: { // BARTENDER
					privelageLevel = credential.BARTENDER;
					break;
				}
				case 5: { // COOK
					privelageLevel = credential.COOK;
					break;
				}
				case 6: { // CHEF
					privelageLevel = credential.CHEF;
					break;
				}
				}
			}
		});
		employees.add(lstPrivelageLevel);

		// first name label
		JLabel lblFirstName = new JLabel("First name:");
		lblFirstName.setBounds(60, 46, 150, 20);
		employees.add(lblFirstName);

		// first name field
		final JTextField fldFirstName = new JTextField();
		fldFirstName.setBounds(60, 66, 150, 20);
		fldFirstName.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				firstName = fldFirstName.getText();
			}
		});
		employees.add(fldFirstName);

		// last name label
		JLabel lblLastName = new JLabel("Last name:");
		lblLastName.setBounds(60, 91, 150, 20);
		employees.add(lblLastName);

		// last name field
		final JTextField fldLastName = new JTextField();
		fldLastName.setBounds(60, 111, 150, 20);
		fldLastName.addFocusListener(new FocusAdapter() {
			@Override
			public void focusLost(FocusEvent arg0) {
				lastName = fldLastName.getText();
			}
		});
		employees.add(fldLastName);

		// passkey label
		JLabel lblPasskey = new JLabel("Passkey:");
		lblPasskey.setBounds(220, 91, 150, 20);
		employees.add(lblPasskey);

		// passkey field
		final JPasswordField fieldPass = new JPasswordField();
		fieldPass.setBounds(220, 111, 150, 20);
		fieldPass.addFocusListener(new FocusAdapter() {
			@SuppressWarnings("deprecation")
			@Override
			public void focusLost(FocusEvent arg0) {
				try {
					passkey = Integer.parseInt(fieldPass.getText());
				} catch (Exception e) {

				}
			}
		});
		employees.add(fieldPass);

		// employee id label
		JLabel lblEmployeeID = new JLabel("Employee ID #:");
		lblEmployeeID.setBounds(137, 137, 150, 20);
		employees.add(lblEmployeeID);

		// employee id field
		JTextField fldEmployeeID = new JTextField(generateEmpID());
		fldEmployeeID.setBounds(137, 157, 150, 20);
		fldEmployeeID.setEditable(false);
		employees.add(fldEmployeeID);
	}

	// generate an employee ID
	String generateEmpID() {
		String empID;
		int tempID = 0;
		employee temp;

		
		// look through all employees for the highes existing empID
		for (int i = 0; i < db.getEmployees().size(); i++) {
			temp = db.getEmployees().get(i);

			try {
				int tempInt = Integer.parseInt(temp.getIdNum());
				if (tempInt > tempID)
					tempID = Integer.parseInt(temp.getIdNum()); // turn id into
																// int from
																// string
			} catch (NumberFormatException nfe) {
				System.err.println("error with generating id, tempID is " + tempID + " getIDNum is " + temp.getIdNum());
			}
		}

		// sets up employee ID as a string
		empID = String.valueOf(++tempID);

		// add 0's accordingly
		if (tempID < 1000) {
			empID = "0".concat(empID);
			if (tempID < 100) {
				empID = "0".concat(empID);
				if (tempID < 10) {
					empID = "0".concat(empID);
				}
			}
		}

		// return the next available empID
		return empID;
	}

	// this is the pane for all settings and database related items
	private void DatabasePane() {
		// settings
		{
			settings = new JPanel();
			settings.setLayout(new GridLayout(4, 2));
			settings.setVisible(true);
			settings.repaint();

			// TODO this should export a database object that can be opened via
			// the load button backup button
			btnBackupDatabase = new JButton("Backup Database");
			btnBackupDatabase.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
			
				}
			});
			btnBackupDatabase.setEnabled(false);
			settings.add(btnBackupDatabase);

			// TODO this should export the current database to csv, the class is
			// setup, it just needs programming
			// export button
			btnExportDatabase = new JButton("Export Database");
			btnExportDatabase.setEnabled(true);
			settings.add(btnExportDatabase);

			// TODO this should load over the current databse load database
			// button
			btnLoadDatabase = new JButton("Load Database");
			btnLoadDatabase.setEnabled(false);
			settings.add(btnLoadDatabase);

			// TODO this should create a new database new database button
			btnNewDatabase = new JButton("NEW Database");
			btnNewDatabase.setEnabled(true);
			settings.add(btnNewDatabase);

			// TODO ... this should delete the current data base delete database
			// button
			btnChngTaxRate = new JButton("Change Tax Rate");
			settings.add(btnChngTaxRate);

			// allows a change to the restaurant hours change hours button
			btnHours = new JButton("Change hours");
			settings.add(btnHours);

			// allows a change/addition to tables in restaurant add table button
			btnNewTableChair = new JButton("New Table/Chair");
			settings.add(btnNewTableChair);

			// TODO pretty much same as add table button.. but opposite remove
			// table button
			btnRemoveTableChair = new JButton("Remove Table/Chair");
			settings.add(btnRemoveTableChair);
		}

		// Backup database panel
		{
			backupDatabase = new JPanel();
			backupDatabase.setLayout( new GridLayout());
			
			// cancel button
			btnCancelTable = new JButton("CANCEL Table");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			backupDatabase.add(btnCancelTable);
		}

		// load database
		{
			loadDatabase = new JPanel();

			// cancel button
			btnCancelTable = new JButton("CANCEL Table");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			loadDatabase.add(btnCancelTable);
		}

		// change tax rate
		{
			changeTaxRate = new JPanel();
			changeTaxRate.setLayout(new GridLayout(2, 2));

			// Tax rate label
			JLabel lblTaxRate = new JLabel("Tax rate");
			changeTaxRate.add(lblTaxRate);

			// dropdown menu with tax rates
			taxRatesField = new JTextField();
			taxRatesField.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent arg0) {
					try {
						taxRate = Double.parseDouble(taxRatesField.getText());
					} catch (Exception e) {

					}
				}
			});
			changeTaxRate.add(taxRatesField);

			// save button
			btnSaveTaxRate = new JButton("Save Tax Rate");
			changeTaxRate.add(btnSaveTaxRate);

			// cancel button
			btnCancelTable = new JButton("CANCEL Tax Change");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			changeTaxRate.add(btnCancelTable);
			
			// switch to change tax rate pane
			btnChngTaxRate.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// switch to the correct pane
					tabbedPane.setComponentAt(3, changeTaxRate);
					repaint();
				}
			});
		}

		// change hours
		{
			changeHours = new JPanel();
			changeHours.setLayout(new GridLayout(3, 2));
			
			// add opening time label
			JLabel lblOpeningTime = new JLabel("Opening");
			changeHours.add(lblOpeningTime);
			
			// add opening combobox of times
			startTime = new ArrayList<String> ();
			for(int i = 1; i <= 24; i++){
				for(int j = 0; j<= 59; j+=15){
					if(i > 12){
						if(j==0)
							startTime.add((i-12) + ":" + "00 PM");
						else
							startTime.add((i-12) + ":" + j + " PM");
					}
					else{
						if(j==0)
							startTime.add((i) + ":" + "00 AM");
						else
							startTime.add((i) + ":" + j + " AM");
					}
				}
			}
			//System.out.println("The start times will be " + startTime);
			jcbOpeningTime = new JComboBox(startTime.toArray());
			//jcbClosingTime = new JComboBox();
			jcbOpeningTime.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent e) {
					String time = (String) jcbOpeningTime.getSelectedItem();
					// when this number has been selected setup the next one starting where this one ends
					//System.out.println("Time not formated " + time);
					hoursStart = Integer.parseInt(time.substring(0, time.indexOf(":")));
					minStart = Integer.parseInt(time.substring(time.indexOf(":")+1, time.length()-3));
					if(time.indexOf("PM") > 0){
						hoursStart = hoursStart+12;
					}
					
					//System.out.println("time after formatting " + hoursStart + " " + minStart);
					//hoursOfOpOpen = new RestaurantTime(hoursStart,minStart);//int hour, int min
				}
			});
			changeHours.add(jcbOpeningTime);
			
			// add closing label
			JLabel lblClosingTime = new JLabel("Closing");
			changeHours.add(lblClosingTime);
			
			// add opening combobox of times
			endTime = new ArrayList<String> ();
			for(int i = 1 /*hoursStart*/; i <= 24; i++){
				for(int j = 0 /*minStart*/; j<= 59; j+=15){
					if(i > 12){
						if(j==0)
							endTime.add((i-12) + ":" + "00 PM");
						else
							endTime.add((i-12) + ":" + j + " PM");
					}
					else{
						if(j==0)
							endTime.add((i) + ":" + "00 AM");
						else
							endTime.add((i) + ":" + j + " AM");
					}
				}
			}
			jcbClosingTime = new JComboBox(endTime.toArray());
			jcbClosingTime.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent e) {
					String time = (String) jcbClosingTime.getSelectedItem();
					// when this number has been selected setup the next one starting where this one ends
					//System.out.println("End time before format");
					hoursEnd = Integer.parseInt(time.substring(0, time.indexOf(":")));
					minEnd = Integer.parseInt(time.substring(time.indexOf(":")+1, time.length()-3));
					if(time.indexOf("PM") > 0){
						hoursEnd = hoursEnd+12;
					}
					
					//System.out.println("end time - time after formatting " + hoursEnd + " " + minEnd);
					//hoursOfOpClose = new RestaurantTime(hoursEnd,minEnd);//int hour, int min
				}
			});
			changeHours.add(jcbClosingTime);
			
			btnSaveHoursOfOp = new JButton("Save new hours");
			changeHours.add(btnSaveHoursOfOp);
						
			// cancel button
			btnCancelTable = new JButton("CANCEL Table");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			changeHours.add(btnCancelTable);
			
			// switch to change hours
			btnHours.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch change hours pane");
					tabbedPane.setComponentAt(3, changeHours);
					repaint();
				}
			});
		}

		// add tables panel
		{
			addTables = new JPanel();
			addTables.setLayout(new GridLayout(3, 2));
			// table type
			lblTableType = new JLabel("Table or Chair Type");
			addTables.add(lblTableType);

			cmbTableType = new JComboBox(TableType.values());
			cmbTableType.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent e) {
					switch (cmbTableType.getSelectedIndex()) {
					case 0: { // bar stool
						tableType = TableType.BAR_STOOL;
						btnMakeTable.setText("Add Stool");
						break;
					}
					case 1: { // two person round
						tableType = TableType.TWO_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 2: { // 4 person round
						tableType = TableType.FOUR_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 3: { // 6 person round
						tableType = TableType.SIX_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 4: { // 2 person rect
						tableType = TableType.TWO_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 5: { // 4 person rect
						tableType = TableType.FOUR_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 6: { // 6 person rect
						tableType = TableType.SIX_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 7: { // 8 person rect
						tableType = TableType.EIGHT_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					}
				}
			});
			addTables.add(cmbTableType);

			// table type
			lblTableQuant = new JLabel("Add x amount");
			addTables.add(lblTableQuant);

			txtFldQuant = new JTextField();
			txtFldQuant.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent arg0) {
					tableQuant = Integer.parseInt(txtFldQuant.getText());
				}
			});
			addTables.add(txtFldQuant);
			txtFldQuant.setColumns(10);

			// create new table
			btnMakeTable = new JButton("Add Table");
			addTables.add(btnMakeTable);
			

			// cancel button
			btnCancelTable = new JButton("CANCEL Table");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			addTables.add(btnCancelTable);
			
			// switch to add tables button
			btnNewTableChair.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// switch to the correct pane
					tabbedPane.setComponentAt(3, addTables);
					repaint();
				}
			});
		}

		// remove tables
		{
			removeTables = new JPanel();
			removeTables.setLayout(new GridLayout(3, 2));
			// table type
			lblTableType = new JLabel("Table or Chair Type");
			removeTables.add(lblTableType);

			cmbTableType = new JComboBox(TableType.values());
			cmbTableType.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent e) {
					switch (cmbTableType.getSelectedIndex()) {
					case 0: { // bar stool
						tableType = TableType.BAR_STOOL;
						btnMakeTable.setText("Add Stool");
						break;
					}
					case 1: { // two person round
						tableType = TableType.TWO_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 2: { // 4 person round
						tableType = TableType.FOUR_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 3: { // 6 person round
						tableType = TableType.SIX_PERSON_ROUND;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 4: { // 2 person rect
						tableType = TableType.TWO_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 5: { // 4 person rect
						tableType = TableType.FOUR_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 6: { // 6 person rect
						tableType = TableType.SIX_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					case 7: { // 8 person rect
						tableType = TableType.EIGHT_PERSON_RECT;
						btnMakeTable.setText("Add Table");
						break;
					}
					}
				}
			});
			removeTables.add(cmbTableType);

			// table type
			lblTableQuant = new JLabel("Remove x amount");
			removeTables.add(lblTableQuant);

			txtFldRemoveQuant = new JTextField();
			txtFldRemoveQuant.addFocusListener(new FocusAdapter() {
				@Override
				public void focusLost(FocusEvent arg0) {
					tableQuant = Integer.parseInt(txtFldRemoveQuant.getText());
				}
			});
			removeTables.add(txtFldRemoveQuant);
			txtFldRemoveQuant.setColumns(10);

			// remove table
			btnRemoveTable = new JButton("Remove Table");
			removeTables.add(btnRemoveTable);

			// cancel button
			btnCancelTable = new JButton("CANCEL Table");
			btnCancelTable.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent e) {
					System.out.println("switch back to settings pane");
					tabbedPane.setComponentAt(3, settings);
					repaint();
				}
			});
			removeTables.add(btnCancelTable);
			
			// switch to remove tables button
			btnRemoveTableChair.addActionListener(new ActionListener() {
				public void actionPerformed(ActionEvent arg0) {
					// switch to the correct pane
					tabbedPane.setComponentAt(3, removeTables);
					repaint();
				}
			});
		}

		// actions
		/*
		 * btnBackupDatabase.addActionListener(new ActionListener() { public
		 * void actionPerformed(ActionEvent arg0) {
		 * 
		 * } });
		 * 
		 * btnExportDatabase.addActionListener(new ActionListener() { public
		 * void actionPerformed(ActionEvent arg0) { // new exportDB(db); } });
		 * 
		 * btnLoadDatabase.addActionListener(new ActionListener() { public void
		 * actionPerformed(ActionEvent arg0) { // new importDB(db); } });
		 * 
		 * btnNewDatabase.addActionListener(new ActionListener() { public void
		 * actionPerformed(ActionEvent arg0) {
		 * 
		 * } });
		 * 
		 * btnDeleteDatabase.addActionListener(new ActionListener() { public
		 * void actionPerformed(ActionEvent arg0) {
		 * 
		 * } });
		 * 
		 * btnHours.addActionListener(new ActionListener() { public void
		 * actionPerformed(ActionEvent arg0) {
		 * 
		 * } });
		 */
	}

	// notes pane
	public void NotesPane() {
		notes = new JPanel();
		notes.setLayout(new GridLayout(3, 2));

		System.out.println("notes is " + notes1);
		
		// add label and field for notes 1
		notes.add(new JLabel("Custom Field 1:"));
		txtNotes1 = new TextArea();
		notes.add(txtNotes1);

		// add label and field for notes 2
		notes.add(new JLabel("Custom Field 2:"));
		txtNotes2 = new TextArea();
		notes.add(txtNotes2);

		// add label and field for notes 3
		notes.add(new JLabel("Custom Field 3:"));
		txtNotes3 = new TextArea();
		notes.add(txtNotes3);
	}

	// creates the employee nodes
	public void createNodes(DefaultMutableTreeNode top) {
		administratorCred = new DefaultMutableTreeNode(credential.ADMINISTRATOR);
		managerCred = new DefaultMutableTreeNode(credential.MANAGER);
		hostessCred = new DefaultMutableTreeNode(credential.HOSTESS);
		serverCred = new DefaultMutableTreeNode(credential.SERVER);
		bartenderCred = new DefaultMutableTreeNode(credential.BARTENDER);
		cookCred = new DefaultMutableTreeNode(credential.COOK);
		chefCred = new DefaultMutableTreeNode(credential.CHEF);

		top.add(administratorCred);
		top.add(managerCred);
		top.add(hostessCred);
		top.add(serverCred);
		top.add(bartenderCred);
		top.add(cookCred);
		top.add(chefCred);

		/*
		 * //TODO for (int i = 0; i < db.employees.size(); i++) { switch
		 * (db.employees.get(i).getPrivelageLevel()) { case ADMINISTRATOR: {
		 * administratorCred.add(new DefaultMutableTreeNode(db.employees
		 * .get(i))); break; } case MANAGER: { managerCred .add(new
		 * DefaultMutableTreeNode(db.employees.get(i))); break; } case HOSTESS:
		 * { hostessCred .add(new DefaultMutableTreeNode(db.employees.get(i)));
		 * break; } case SERVER: { serverCred.add(new
		 * DefaultMutableTreeNode(db.employees.get(i))); break; } case
		 * BARTENDER: { bartenderCred.add(new
		 * DefaultMutableTreeNode(db.employees .get(i))); break; } case COOK: {
		 * cookCred.add(new DefaultMutableTreeNode(db.employees.get(i))); break;
		 * } case CHEF: { chefCred.add(new
		 * DefaultMutableTreeNode(db.employees.get(i))); break; } } }
		 */
	}

	@Override
	public void windowGainedFocus(WindowEvent arg0) {
	}

	@Override
	public void windowLostFocus(WindowEvent e) {
		this.dispose(); // close window if not being used
	}

	@Override
	public void windowActivated(WindowEvent arg0) {
	}

	@Override
	public void windowClosed(WindowEvent arg0) {
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
	}

	@Override
	public void windowDeactivated(WindowEvent arg0) {
	}

	@Override
	public void windowDeiconified(WindowEvent arg0) {
	}

	@Override
	public void windowIconified(WindowEvent arg0) {
	}

	@Override
	public void windowOpened(WindowEvent arg0) {
	}

	protected int generateTableID() {
		int tempID = 0;
		Table temp;

		/*
		// look through all employees for the highes existing empID
		for (int i = 0; i < db.getTables().size(); i++) {
			temp = db.getTables().get(i);

			try {
				int tempInt = temp.getTableID();
				if (tempInt > tempID)
					tempID = tempInt;

			} catch (NumberFormatException nfe) {
				System.err.println("error with generating table id");
			}
		}
		*/
		return tempID;
	}

	protected int generateStoolID() {
		int tempID = 0;
		Table temp;

		
		// look through all employees for the highes existing empID
		for (int i = 0; i < db.getBarStools().size(); i++) {
			temp = db.getBarStools().get(i);

			try {
				int tempInt = temp.getTableID();
				if (tempInt > tempID)
					tempID = tempInt;

			} catch (NumberFormatException nfe) {
				System.err.println("error with generating table id");
			}
		}
		
		return tempID;
	}

	protected Table getTable() {
		if (tableType == TableType.BAR_STOOL)
			return new Table(generateStoolID(), tableType,DinnerEvent.AVAILABLE);
		else
			return new Table(generateTableID(), tableType,DinnerEvent.AVAILABLE);
	}
	
	public int getHoursStart(){
		return hoursStart;
	}
	public int getMinStart(){
		return minStart;
	}
	public int getHoursEnd(){
		return hoursEnd;
	}
	public int getMinEnd(){
		return minEnd;
	}
}